Skip to content

Add Playwright E2E tests for SSH Command integration#10

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-playwright-e2e-tests-ssh-command
Draft

Add Playwright E2E tests for SSH Command integration#10
Copilot wants to merge 2 commits intomainfrom
copilot/add-playwright-e2e-tests-ssh-command

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

Adds a tests/playwright/ suite covering the full SSH Command integration lifecycle against real SSH test servers provided by the docker-compose environment.

Structure

tests/playwright/
├── conftest.py               # Shared fixtures
├── test_integration_setup.py # Config flow, single-instance guard, teardown
├── test_command_execution.py # Command execution against live SSH servers
├── test_services.py          # HA service interface (registration, schema, responses)
├── test_frontend.py          # Browser-based UI smoke tests
├── test_configuration.py     # Timeout, auth, known_hosts, multi-server
├── test_security.py          # Auth failures, unauthenticated API, credential validation
├── requirements.txt          # Pinned deps
└── README.md

Key fixture design (conftest.py)

  • ha_token — session-scoped; fetches a real HA access token via the login flow with retry logic (wait_for_ha)
  • context — authenticated Playwright browser context; token injected into localStorage via json.dumps-escaped JS to avoid injection
  • ensure_integration — function-scoped; sets up the SSH Command config entry before each test, tears it down after; keeps tests idempotent and independent
  • ha_apirequests.Session with ****** for direct REST API calls (faster than browser for non-UI assertions)
  • ssh_server_1 / ssh_server_2 — driven by SSH_HOST, SSH_PORT_1/2, SSH_USER, SSH_PASSWORD env vars (defaults match the docker-compose setup)

Coverage highlights

  • Config flow creates entry; second attempt aborts (single_instance_allowed)
  • ssh_command.execute response shape: output, error, exit_status
  • Validation errors (missing auth, missing command+input, known_hosts with check_known_hosts=False, nonexistent key file) all return HTTP 400
  • Timeout enforcement: sleep 60 with timeout=2 returns 400
  • Unauthenticated API call returns 401
  • Both SSH test servers exercised independently
Original prompt

Goal

Add comprehensive Playwright end-to-end tests for the SSH Command Home Assistant custom component.

Background

SSH Command is a Home Assistant custom component that allows executing SSH commands on remote servers. This integration needs thorough E2E testing using Playwright to ensure all functionality works correctly with SSH test servers.

Test Environment

Tests should connect to SSH test servers provided by the docker-compose setup:

  • SSH Test Server 1: ssh_docker_test:2222 (user: foo, password: pass)
  • SSH Test Server 2: ssh_docker_test:2223 (user: foo, password: pass)

Requirements

Create Playwright tests in the tests/playwright directory that cover:

  1. Integration Setup Tests (test_integration_setup.py):

    • Test adding SSH Command integration via config flow
    • Test SSH connection validation
    • Test authentication (password and key-based)
    • Verify integration appears in the integrations list
    • Test connection error handling
  2. Command Execution Tests (test_command_execution.py):

    • Test executing simple commands (e.g., echo, pwd)
    • Test command with output capture
    • Test command with error handling
    • Test commands with different return codes
    • Test long-running commands
    • Test command timeout handling
  3. Service Tests (test_services.py):

    • Test ssh_command.send service
    • Test service with different command types
    • Test service response handling
    • Test service error states
    • Verify command execution logging
  4. Frontend Tests (test_frontend.py):

    • Test SSH Command card/interface rendering (if applicable)
    • Test manual command execution via UI
    • Test command history display
    • Test connection status display
  5. Configuration Tests (test_configuration.py):

    • Test updating SSH configuration
    • Test changing SSH credentials
    • Test port configuration
    • Test timeout settings
    • Test adding/removing multiple SSH connections
  6. Security Tests (test_security.py):

    • Test credential storage security
    • Test connection encryption
    • Test invalid credential handling
    • Test SSH key validation

Technical Details

  • Use Playwright with Python
  • Create a conftest.py with fixtures for:
    • Home Assistant instance connection
    • SSH test server connections
    • Authentication token management
    • Browser context with Home Assistant session
    • Integration setup/teardown
  • Use environment variables for configuration:
    • HOMEASSISTANT_URL (default: http://homeassistant:8123)
    • SSH_HOST (default: ssh_docker_test)
    • SSH_PORT_1 (default: 2222)
    • SSH_PORT_2 (default: 2223)
    • SSH_USER (default: foo)
    • SSH_PASSWORD (default: pass)
  • Add proper waits for async SSH operations
  • Include error handling and retry logic
  • Add comprehensive assertions

File Structure

tests/
└── playwright/
    ├── conftest.py
    ├── test_integration_setup.py
    ├── test_command_execution.py
    ├── test_services.py
    ├── test_frontend.py
    ├── test_configuration.py
    ├── test_security.py
    └── README.md

Additional Files

Create:

  • tests/playwright/README.md - Documentation on how to run the tests
  • tests/playwright/requirements.txt - Python dependencies for tests

Notes

  • Tests should be idempotent and not depend on each other
  • Clean up SSH connections after tests
  • Use meaningful test names and add docstrings
  • Handle SSH authentication properly
  • Tests should work with the docker-compose setup provided
  • Test actual SSH command execution against test servers
  • Verify command output is correctly captured and returned

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: I have mutliple repositories containing Home Assistant custom components (@gensyn/task_tracker, @gensyn/ssh_command, @gensyn/ssh_docker) that I want to thorougly test using Playwright. For that I plan to spin up a Home Assistant instance in a Docker container solely for testing purposes, but I need a target for testing SSH servers and Docker hosts as well. For that I want to create a Docker container, that uses Docker-in-Docker to spin up two instances of @billchurch/ssh_test. This way, the outer Docker container can be the target of SSH Docker, and the contained SSH servers can be used for testing SSH Command. Task Tracker does not have outside dependencies.
Create a Dockerfile file and a docker-compose.yaml file that serve my described purpose and provide them here.
After that, create Playwright tests for each of my mentioned repositories. Put them in their respective repository in a new branch under "tests/playwright" and create a pull request for each repository.

Assistant: I'll help you set up the testing infrastructure and create Playwright tests for your Home Assistant custom components. Let me start by gathering information about your repositories and then provide the Docker configuration files and create th...

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
Copilot AI changed the title [WIP] Add comprehensive Playwright end-to-end tests for SSH Command Add Playwright E2E tests for SSH Command integration Mar 19, 2026
Copilot AI requested a review from gensyn March 19, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants